package com.neuedu.javase.collection;

import java.util.*;

/***
 * 项目名称:  MyJavaSE 
 * 包：  com.neuedu.javase.collection 
 * date:   2025/10/31   14:53  
 * 描述:  
 *  @author : 张金山
 *  作者博客:   https://blog.fulfill.com.cn
 */
public class UseIterator {
    public static void main(String[] args) {

        List list = new LinkedList(Arrays.asList("张三", "李四", "王五"));
        //0
        ListIterator it = list.listIterator(1);  //李四

        boolean success = it.hasPrevious();//判断有没有上一个
        Object previous = it.previous();

        System.out.println("success = " + success);
        System.out.println("previous = " + previous);




        boolean hasNext = it.hasNext();//判断有没有下一个
        Object nextEl = it.next();

        System.out.println("hasNext = " + hasNext);
        System.out.println("nextEl = " + nextEl);


        hasNext = it.hasNext();//判断有没有下一个
        nextEl = it.next();

        System.out.println("hasNext = " + hasNext);
        System.out.println("nextEl = " + nextEl);


        hasNext = it.hasNext();//判断有没有下一个
        nextEl = it.next();

        System.out.println("hasNext = " + hasNext);
        System.out.println("nextEl = " + nextEl);


        hasNext = it.hasNext();//判断有没有下一个
        System.out.println("hasNext = " + hasNext);


        //it.next(); 如果没有元素 会抛出异常
        //Exception in thread "main" java.util.NoSuchElementException
        // 	at java.base/java.util.LinkedList$ListItr.next(LinkedList.java:894)
        // 	at com.neuedu.javase.collection.UseIterator.main(UseIterator.java:52)
        nextEl = it.next();
        System.out.println("nextEl = " + nextEl);


    }
}
